//
//  JZHMyProfileViewController.m
//  极致荟
//
//  Created by hetao on 14-5-14.
//  Copyright (c) 2014年 mac. All rights reserved.
//

#import "JZHMyProfileViewController.h"
#import "JZHMycodeViewController.h"
#import "JZHMyNameUpViewController.h"
#import "JZHISViewController.h"
#import "JZHJobComViewController.h"
#import "JZHAddressViewController.h"
@interface JZHMyProfileViewController ()
{
    NSArray *arr;
    NSArray *cityarr;//城市列表
    NSArray * qxarr;//城市下的区列表。随着城市的变化而变动
    NSMutableDictionary  *xzdic;//最终选定的城市和区
    NSDictionary *predic;//行业
    NSDictionary *zxpredic;//确定选择的行业
    int sex;
    int pickType;//1=性别 2=地区  3=行业 4=出生日期
    
    NSMutableArray *nian;
    NSMutableArray *yue;
    NSMutableArray *ri;
}
@property (weak, nonatomic) IBOutlet UITableView *table;

@end

@implementation JZHMyProfileViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.table reloadData];
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    arr=[[NSArray alloc]initWithObjects:@"头像",@"名字",@"我的二维码",@"我的ID",@"我的收货地址",@"性别",@"出生日期",@"地区",@"公司类型选择",@"公司名称及职位",@"个性签名", nil];
    cityarr=[[NSArray alloc] init];
    qxarr=[[NSArray alloc] init];
    xzdic=[[NSMutableDictionary alloc]init];
    predic=[[NSDictionary alloc] init];
    [self pickhidden];
    [self profHttpData];
    [self citysele];
    [self niandata];
    if(OSVersionIsAtLeastiOS7>=7.0)
    {
        self.automaticallyAdjustsScrollViewInsets=NO;
    }
    self.navigationItem.title=@"个人信息";
    UIButton *leftButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 12, 20)];
    [leftButton addTarget:self action:@selector(leftDrawerButtonPress:) forControlEvents:UIControlEventTouchUpInside];
    [leftButton setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
    UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
    self.navigationItem.leftBarButtonItem = leftBarButton;
    
}

- (void)leftDrawerButtonPress:(UIButton *)but
{
    [UINavigationController Pop:self];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark ---tableview代理---
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return 11;
    
}




- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
  
    static NSString *str=@"adf";
   UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:str];
    if(!cell)
    {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:str];
        
    }
    [self addtableview:cell index:indexPath];
    return cell;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.row==0)
    {
        return 70;
    }else if(indexPath.row!=10)
    {
        return 40;
    }else
    {
        return 70;
    }
}
- (void)addtableview:(UITableViewCell *)cell index:(NSIndexPath *)index
{
      [cell.textLabel setText:arr[index.row]];
    //[cell.textLabel setFont:[UIFont systemFontOfSize:14]];
    [cell.textLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:14]];
    for(UIView * cview in [cell.contentView subviews])
    {
            [cview removeFromSuperview];
       
    }
    NSLog(@"%f",cell.contentView.frame.size.height);
    if(index.row!=3)
    {
       
        if(index.row==0 || index.row==10)
        {
            UIImageView *image=[[UIImageView alloc]initWithFrame:CGRectMake(290, 28, 12, 19)];
//            [image setImage:[UIImage imageNamed:@"地图箭头灰2"]];
            [image setImage:[UIImage imageNamed:@"activity_pointer"]];
            [cell.contentView addSubview:image];

        }else
        {
            UIImageView *image=[[UIImageView alloc]initWithFrame:CGRectMake(290, cell.contentView.frame.size.height/2-12, 12, 19)];
//            [image setImage:[UIImage imageNamed:@"地图箭头灰2"]];
            [image setImage:[UIImage imageNamed:@"activity_pointer"]];
            [cell.contentView addSubview:image];

        }
       
    }
    if(index.row==0)
    {
      
        UIImageView *image=[[UIImageView alloc]initWithFrame:CGRectMake(230, 12, 50, 50)];
        [image setImage:[UIImage imageNamed:@"activity_small_image"]];
        [image.layer setCornerRadius:6.0];
        [image.layer setMasksToBounds:YES];
        [image setTag:9001];
        [cell.contentView addSubview:image];
        [ImageCache imageUrl:[User defuceUser].userHeadImage UiImageview:image];

        
                return;
    }
    
    if(index.row==2)
    {
        [cell.textLabel setText:@"我的二维码"];
        UIImageView *image=[[UIImageView alloc]initWithFrame:CGRectMake(250, 8, 25, 25)];
        [image setImage:[UIImage imageNamed:@"个人信息二维码"]];
        [cell.contentView addSubview:image];
        return;
    }
    
    if (index.row == 4)
    {
        
        UILabel *labAddress = [[UILabel alloc]initWithFrame:CGRectMake(125, 5, 150, 30)];
        [labAddress setFont:[UIFont systemFontOfSize:12]];
        [labAddress setNumberOfLines:2];
        [labAddress setTag:8002];
        [labAddress setTextColor:[UIColor grayColor]];
        [labAddress setTextAlignment:NSTextAlignmentRight];
        [cell.contentView addSubview:labAddress];
        
        return;
    }
    if(index.row==10)
    {
        UITextView *tv=[[UITextView alloc] initWithFrame:CGRectMake(100, 15, 180, 50)];
        
        tv.textAlignment=NSTextAlignmentRight;
        [tv setTextColor:[UIColor grayColor]];
        [tv setUserInteractionEnabled:NO];
        tv.text=[User defuceUser].isStr;
        [cell.contentView addSubview:tv];
        return;
    }
    if(index.row!=4  &&index.row!=9 &&index.row!=10 )
    {
        UILabel *lable=[[UILabel alloc]initWithFrame:CGRectMake(75, 8, 200, 20)];
        [lable setTextAlignment:NSTextAlignmentRight];
        [lable setFont:[UIFont systemFontOfSize:12.0]];
        [lable setTextColor:[UIColor grayColor]];
        
        if(index.row==1)
        {
            lable.text=[User defuceUser].name;
            [cell.contentView addSubview:lable];
            return;
        }
        
        if(index.row==3)
        {
            lable.text=@"TIng1956";
             [cell.contentView addSubview:lable];
            return;
        }
        if(index.row==5)
        {
            if([User defuceUser].sex==0)
            {
                lable.text=@"女";
            }else
            {
                lable.text=@"男";
            }
            [lable setTag:9005];
             [cell.contentView addSubview:lable];
           
            return;
        }
        if(index.row==6)
        {
            NSDateFormatter *form=[[NSDateFormatter alloc] init];
            [form setDateFormat:@"yyyy年MM月dd日"];
            lable.text=[form stringFromDate:[User defuceUser].userdate];
            [lable setTag:9013];
            [cell.contentView addSubview:lable];
            return;
        }
        if(index.row==7)
        {
            NSString *str=[[User defuceUser].locationdic objectForKey:@"cityName"];
            [lable setTag:9006];
            str=  [str stringByAppendingFormat:@" %@",[[User defuceUser].locationdic objectForKey:@"quName"]];
            lable.text=str;
             [cell.contentView addSubview:lable];
            return;
        }
        
        if(index.row==8)
        {
            [lable setTag:9007];
            lable.text=[[User defuceUser].persdic objectForKey:@"name"];
            [cell.contentView addSubview:lable];
            return;
        }
    }
   
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    switch (indexPath.row) {
        case 0:
        {
            //调用照相或相册
            UIActionSheet *actionshee=[[UIActionSheet alloc]initWithTitle:@"操作" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"照相" otherButtonTitles:@"相册", nil];
            [actionshee showInView:[UIApplication sharedApplication].keyWindow];
        }
            break;
        case 1:
            [self presentViewController:[[JZHMyNameUpViewController alloc] init] animated:YES completion:^{
                
            }];
            break;
        case 2:
            [self.navigationController pushViewController:[[JZHMycodeViewController alloc]init] animated:YES];
            break;
            
        case 4:
        {
          [self.navigationController pushViewController:[[JZHAddressViewController alloc]init] animated:YES];        }
            break;
         
        case 5:
        {
            
            pickType=1;
            [self.citypick reloadAllComponents];
            [self pickshow];

        }
            break;
            
        case 6:
        {
            pickType=4;
            [self.citypick reloadAllComponents];
            [self.citypick reloadInputViews];
            [self pickshow];
        }
            break;
        case 7:
            pickType=2;
            
            
            [self qxdic:cityarr[0]];
            [self.citypick reloadAllComponents];
            [self.citypick reloadInputViews];
            [self.citypick selectRow:0 inComponent:0 animated:NO];
            [self.citypick selectRow:0 inComponent:1 animated:NO];
            [xzdic setObject:[cityarr[0] objectForKey:@"id"] forKey:@"cid"];
            [xzdic setObject:[cityarr[0] objectForKey:@"name"] forKey:@"cityName"];
            [xzdic setObject:[qxarr[0] objectForKey:@"id"] forKey:@"quid"];
            [xzdic setObject:[qxarr[0] objectForKey:@"name"] forKey:@"quName"];
            [self pickshow];
            break;
        case 8:
            pickType=3;
             [self.citypick reloadAllComponents];
            [self pickshow];
            break;
        case 9:
//            [self presentViewController:[[JZHJobComViewController alloc] init] animated:YES completion:^{
//                
//            }];
            [self.navigationController pushViewController:[[JZHJobComViewController alloc] init] animated:YES];
            break;
        case 10://个性签名
            [self.navigationController pushViewController:[[JZHISViewController alloc] init] animated:YES];
            break;
        default:
            break;
    }
}


#pragma mark -----请求后台数据-----
- (void)cityHttpData:(NSString *)path
{
    NSDictionary *dic=[[NSDictionary alloc] initWithObjectsAndKeys:[NSNumber numberWithInt:0],@"parentId", nil];
    [HttpRequest httpRequestPost:JZHHTTPURL(@"myInformation/districtList") parameters:dic block:^(id data, HttpReturnCode rerurncode) {
        if(rerurncode==0)
        {
            cityarr=[[data objectForKey:@"data"] objectForKey:@"list"];
            [self qxdic:cityarr[0]];
            [self.citypick reloadAllComponents];
            [cityarr writeToFile:path atomically:YES];
                NSLog(@"%@",data);
        }
    }];
}

- (void)profHttpData
{
    [HttpRequest httpRequestPost:JZHHTTPURL(@"myInformation/professionList") parameters:nil block:^(id data, HttpReturnCode rerurncode) {
        if(rerurncode==0)
        {
            if([[data objectForKey:@"data"] isKindOfClass:[NSDictionary class]])
            {
                predic=[data objectForKey:@"data"];
                zxpredic=[[NSDictionary alloc] initWithObjectsAndKeys:[predic allValues][0],@"preName",[predic allKeysForObject:[predic allValues][0]][0],@"preid", nil];
            }
            NSLog(@"%@",data);
        }
    }];
}

#pragma mark - 性别的PickerViewdelegate和PickerViewDatasouce
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    if(pickType==1 || pickType==3)
    {
        return 1;
    }
    if(pickType==2)
    {
        return 2;
    }
    
    if(pickType==4)
    {
        return 3;
    }
    return 0;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    if(pickType==1)
    {
        return 2;
    }
    
    if(pickType==2)
    {
        if(component==1)
        {
            return qxarr.count;
            
        }else
        {
            return cityarr.count;
        }
    }
    
    if(pickType==3)
    {
        return predic.allValues.count;
    }
    
    if(pickType==4)
    {
        if(component==0)
        {
            return nian.count;
        }
        if(component==1)
        {
            return yue.count;
        }
        if(component==2)
        {
            return ri.count;
        }
    }
    return 0;
}

- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
{
    if(pickType==1)
    {
        return 50;
    }
    else
    {
        return 30;
    }
    return 0;
}

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
   
    if(pickType==1)
    { UILabel *label = [[UILabel alloc]init];
        [label setBackgroundColor:[UIColor colorWithRed:242/255.0 green:242/255.0 blue:242/255.0 alpha:1]];
        if (row == 0)
        {
            [label setText:@"男"];
        }
        else
        {
            [label setText:@"女"];
        }
        
        [label setTextAlignment:NSTextAlignmentCenter];
        return label;

    }
    
    if(pickType==2)
    {
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 160, 20)];
        label.textAlignment=NSTextAlignmentCenter;
        if(component==0)
        {
            
            label.text=[cityarr[row] objectForKey:@"name"];
        }else
        {
            label.text=[qxarr[row] objectForKey:@"name"];
        }
        return label;

    }
    
    if(pickType==3)
    {
        UILabel *label = [[UILabel alloc]init];
        label.textAlignment=NSTextAlignmentCenter;
        label.text=predic.allValues[row];
        return label;
    }
    
    if(pickType==4)
    {
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 103, 20)];
        label.textAlignment=NSTextAlignmentCenter;
       
        if(component==0)
        {
             NSNumber *nmber=nian[row];
            label.text=[NSString stringWithFormat:@"%d",nmber.intValue] ;
            return label;
        }
        if(component==1)
        {
            NSNumber *nmber=yue[row];
            label.text=[NSString stringWithFormat:@"%d",nmber.intValue] ;
            return label;
        }
        if(component==2)
        {
            NSNumber *nmber=ri[row];
            label.text=[NSString stringWithFormat:@"%d",nmber.intValue] ;            return label;
        }
    }
    
    return nil;
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    if(pickType==1)
    {
    
        if (row == 0)
        {
            sex=1;
        }
        else
        {
             sex=0;
        }

    }
    
    if(pickType==2)
    {
         UILabel *lab=(UILabel *)[pickerView viewForRow:row forComponent:component];
        if(component==0)
        {
           
            int cid= [[cityarr [row] objectForKey:@"id"] intValue];
            [xzdic setObject:[NSNumber numberWithInt:cid] forKey:@"cid"];
            [xzdic setObject:lab.text forKey:@"cityName"];
            [self qxdic:cityarr [row]];
            [pickerView selectRow:0 inComponent:1 animated:NO];
            [pickerView reloadAllComponents];
        }else
        {
           
            if([qxarr[row] isKindOfClass:[NSDictionary class]])
            {
                 [xzdic setObject:lab.text forKey:@"quName"];
                    int cid= [[qxarr[row] objectForKey:@"id"] intValue];
                  [xzdic setObject:[NSNumber numberWithInt:cid] forKey:@"quid"];
            }
            
        }
    }
    
    if(pickType==3)
    {
          UILabel *lab=(UILabel *)[pickerView viewForRow:row forComponent:component];
         zxpredic=[[NSDictionary alloc] initWithObjectsAndKeys:lab.text,@"preName",[predic allKeysForObject:lab.text][0],@"preid", nil];
        
    }
    
    if(pickType==4)
    {
        if(component!=2)
        {
            UILabel *lab1=(UILabel *)[pickerView viewForRow:row forComponent:0];
            UILabel *lab2=(UILabel *) [pickerView viewForRow:[pickerView selectedRowInComponent:1] forComponent:1];
           
            [self ri:[lab1.text intValue] yue:[lab2.text intValue]];
            [self.citypick reloadComponent:2];
        }
    }
}




#pragma mark - 调用相机或相册的方法
#pragma mark actionsheet 代理方法实现-------------
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if(buttonIndex==1)//找一张
    {
        
        if(![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]){
            [[[UIAlertView alloc]initWithTitle:@"提示" message:@"当前相册不可用" delegate:Nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil] show];
            return;
        }
        UIImagePickerController *imagecont=[[UIImagePickerController alloc]init];
        imagecont.delegate=self;
        
        [self presentViewController:imagecont animated:YES completion:^{}];
        
    }else if (buttonIndex==0)//照一张
    {
        if(![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
            [[[UIAlertView alloc]initWithTitle:@"提示" message:@"当前相机不可用" delegate:Nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil] show];
            
            return;
        }
        UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
        [imagePickerController setSourceType:UIImagePickerControllerSourceTypeCamera];
        [imagePickerController setDelegate:self];
        [imagePickerController setAllowsEditing:YES];
        [self presentViewController:imagePickerController animated:YES completion:^{}];
        
        
    }
    
}

#pragma mark 相册 代理方法实现-------------
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *img;
    NSLog(@"%@",info);
    if(picker.sourceType == UIImagePickerControllerSourceTypeCamera){
        img=[info objectForKey:UIImagePickerControllerEditedImage];
    }else {
        img=[info objectForKey:UIImagePickerControllerOriginalImage];
    }
    CGRect rect=CGRectMake(60, 150, 200, 200);
    VPImageCropperViewController *vp=[[VPImageCropperViewController alloc] initWithImage:img cropFrame:rect limitScaleRatio:8.0];
    vp.delegate=self;
    [picker dismissViewControllerAnimated:NO completion:^{
        [self presentViewController:vp animated:NO completion:^{
            
        }];
    }];
    
    
   
}
- (void)imageCropper:(VPImageCropperViewController *)cropperViewController didFinished:(UIImage *)editedImage
{
    UIImageView *icon = (UIImageView *)[self.table viewWithTag:9001];
    [icon setImage:editedImage];
    [HttpRequest uploadTopicFile:[NSArray arrayWithObjects:UIImageJPEGRepresentation(icon.image, 1), nil] URL:JZHHTTPURL(@"myInformation/uploadImg") key:@"informationImage" block:^(id data, HttpReturnCode rerurncode) {
        if(rerurncode==0)//上传成功后，删除原有的用户头像缓存
        {
            [ImageCache dorpImage:[User defuceUser].userHeadImage];
            [User defuceUser].userHeadImage=[[data objectForKey:@"data"] objectForKey:@"filepath"];
            NSArray *arrs=[[User defuceUser].userHeadImage componentsSeparatedByString:@"/"];
            NSString *imagename=[arrs objectAtIndex:arrs.count-1];
            [ImageCache saveImage:imagename imageData:UIImageJPEGRepresentation(icon.image, 1)];
            [self upUserData:[User defuceUser].userHeadImage key:@"Avatar"];
            NSLog(@"%@",data);
            UIImageView *icon = (UIImageView *)[self.table viewWithTag:9001];
            [icon setImage:editedImage];
        }
    }];
    [cropperViewController dismissViewControllerAnimated:NO completion:^{
        
    }];
}
- (void)imageCropperDidCancel:(VPImageCropperViewController *)cropperViewController
{
    [cropperViewController dismissViewControllerAnimated:NO completion:^{
        
    }];
}
- (void)pickshow
{
    self.pickview.hidden=NO;
    NSLog(@"%f %f ",self.view.frame.size.height,self.citypickview.frame.size.height);
    [UIView animateWithDuration:.3 animations:^{
        [self.citypickview setFrame:CGRectMake(0, self.view.frame.size.height-self.citypickview.frame.size.height-64, self.citypickview.frame.size.width, self.citypickview.frame.size.height)];
    }];
}
- (void)pickhidden
{
    [UIView animateWithDuration:.3 animations:^{
        [self.citypickview setFrame:CGRectMake(0, self.view.frame.size.height, self.citypickview.frame.size.width, self.citypickview.frame.size.height)];
    } completion:^(BOOL finished) {
        self.pickview.hidden=YES;
    }];
}
- (IBAction)ok:(id)sender
{
    if(pickType==1)
    {
        UILabel *label = (UILabel *)[self.table viewWithTag:9005];
        if(sex==1)
        {
            [User defuceUser].sex=1;
            label.text=@"男";
        }else
        {
            [User defuceUser].sex=0;
            label.text=@"女";
        }
        [self upUserData:[NSString stringWithFormat:@"%d",sex] key:@"Sex"];
        
    }
    if(pickType==2)
    {
        [User defuceUser].locationdic=xzdic;
        [self upUserData:[xzdic objectForKey:@"cid"] key:@"City"];
        [self upUserData:[xzdic objectForKey:@"quid"] key:@"Area"];
        NSString *str=[[User defuceUser].locationdic objectForKey:@"cityName"];
        UILabel *lable=(UILabel *)[self.table viewWithTag:9006];
        str=  [str stringByAppendingFormat:@" %@",[[User defuceUser].locationdic objectForKey:@"quName"]];
        lable.text=str;
    }
    if(pickType==3)
    {
        [User defuceUser].persdic=[[NSDictionary alloc] initWithObjectsAndKeys:[zxpredic objectForKey:@"preid"],@"id",[zxpredic objectForKey:@"preName"],@"name", nil];
        [self upUserData:[zxpredic objectForKey:@"preid"] key:@"Profession"];
        UILabel *lable=(UILabel *)[self.table viewWithTag:9007];
        lable.text=[[User defuceUser].persdic objectForKey:@"name"];
    }
    
    if(pickType==4)
    {
        NSString *lable1=[(UILabel *)[self.citypick viewForRow:[self.citypick selectedRowInComponent:0] forComponent:0] text];
        NSString *lable2=[(UILabel *)[self.citypick viewForRow:[self.citypick selectedRowInComponent:1] forComponent:1] text];
        NSString *lable3=[(UILabel *)[self.citypick viewForRow:[self.citypick selectedRowInComponent:2] forComponent:2] text];
        NSString *str=[NSString stringWithFormat:@"%@年%@月%@日",lable1,lable2,lable3];
        
        NSDateFormatter *form=[[NSDateFormatter alloc] init];
        [form setDateFormat:@"yyyy年MM月dd日"];
        [User defuceUser].userdate=[form dateFromString:str];
          UILabel *lable=(UILabel *)[self.table viewWithTag:9013];
        lable.text=str;
        NSLog(@"%@", [User defuceUser].userdate);
        NSNumber *nber=[NSNumber numberWithLongLong:[[User defuceUser].userdate timeIntervalSince1970]];
        [self upUserData:[NSString stringWithFormat:@"%lld", nber.longLongValue]  key:@"Birthday"];
    }
    [self pickhidden];
}
- (IBAction)close:(id)sender
{
    [self pickhidden];

}

- (void)upUserData:(NSString *)value key:(NSString *)key
{
    NSDictionary *dic=[[NSDictionary alloc] initWithObjectsAndKeys:[NSNumber numberWithInt:[User defuceUser].userId],@"userId",key,@"infoType",value,@"editInfo",nil];
    [HttpRequest httpRequestPost:JZHHTTPURL(@"myInformation/editInfo") parameters:dic block:^(id data, HttpReturnCode rerurncode) {
        NSLog(@"%@",data);
    }];
    
}
- (void)citysele
{
    NSString *path=NSHomeDirectory();
    path=[path stringByAppendingString:@"/Documents/MyCityersList.plist"];
    NSArray *arrq=[[NSArray alloc] initWithContentsOfFile:path];
    if(!arrq)
    {
        NSLog(@"没有缓存");
        [self cityHttpData:path];
        
    }else
    {
        cityarr=arrq;
        [self qxdic:cityarr[0]];
        [self.citypick reloadAllComponents];
    }

}
- (void)qxdic:(id)dic
{
    if([dic isKindOfClass:[NSDictionary class]])
    {
        qxarr=[dic objectForKey:@"subDistrict"];
        if(!qxarr)
        {
            [xzdic setObject:@"" forKey:@"quName"];
            [xzdic setObject:[NSNumber numberWithInt:0] forKey:@"quid"];
        }else
        {
            [xzdic setObject:[qxarr [0] objectForKey:@"name"] forKey:@"quName"];
            [xzdic setObject:[qxarr [0] objectForKey:@"id"] forKey:@"quid"];
        }
        
    }else
    {
        qxarr=nil;
    }
    
}

- (void)niandata
{
    NSDate *date=[NSDate date];
    NSDateFormatter *form=[[NSDateFormatter alloc] init];
    [form setDateFormat:@"yyyy"];
    NSString *str=[form stringFromDate:date];
    
    nian=[[NSMutableArray alloc] init];
    for(int i=[str intValue];i>=1920;i--)
    {
        [nian addObject:[NSNumber numberWithInt:i]];
    }
    [self yuedata];
}

- (void)yuedata
{
    yue=[[NSMutableArray alloc] init];
    for(int i=1;i<13;i++)
    {
        [yue addObject:[NSNumber numberWithInt:i]];
    }
    [self ri:1980 yue:1];
}

- (void)ri:(int)niand yue:(int)yued
{
    
    switch (yued) {
        case 1:
            [self ridata:31];
            break;
        case 2:
        {
            if(niand%4==0 && niand%100!=0)
            {
                [self ridata:29];
            }else
            {
               [self ridata:28];
            }
        }
            
            break;
        case 3:
            [self ridata:31];
            break;
        case 4:
            [self ridata:30];
            break;
        case 5:
            [self ridata:31];
            break;
        case 6:
            [self ridata:30];
            break;
        case 7:
            [self ridata:31];
            break;
        case 8:
            [self ridata:31];
            break;
        case 9:
            [self ridata:30];
            break;
        case 10:
            [self ridata:31];
            break;
        case 11:
            [self ridata:30];
            break;
        case 12:
            [self ridata:31];
            break;
        default:
            break;
    }
}
- (void)ridata:(int)row
{
    if(!ri)
    {
        ri=[[NSMutableArray alloc] init];
    }else
    {
        [ri removeAllObjects];
    }
    
    for(int i=1;i<=row;i++)
    {
        [ri addObject:[NSNumber numberWithInt:i]];
    }
}
@end
